﻿app.controller("ngAddAlbumController", function ($scope, $http, $location) {

    $scope.album;

    $scope.saveAlbum = function (album) {
        $http.post("/api/album", album).success(function (data) {
            $location.path("/AlbumDetail/" + data.Id);
        }).error(function (data) {
            console.log(JSON.stringify(data));
        });
    };

    $scope.cancel = function (album) {
        $location.path("/");
    };

});

app.controller("ngEditAlbumController", function ($scope, $http, $location, $routeParams) {

    $scope.album;

    $scope.isEdit = true;

    $http.get("/api/album/detail/" + $routeParams.id).success(function (data) {
        $scope.album = data;
    }).error(function (data) {
        console.log(JSON.stringify(data));
    });

    $scope.saveAlbum = function (album) {
        $http.put("/api/album", album).success(function (data) {
            $location.path("/AlbumDetail/" + data.Id);
        }).error(function (data) {
            console.log(JSON.stringify(data));
        });
    };

    $scope.cancel = function (album) {
        $location.path("/AlbumDetail/" + album.Id);
    };

    $scope.delete = function (album) {
        $http.delete("api/album/", album).success(function (data) {
            $location.path("/");
        }).error(function (data) {
            console.log(JSON.stringify(data));
        });
    }
});